{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ZDT\n",
    "\n",
    "The ZDT <cite data-cite=\"zdt\"></cite> problem suite is based on the construction process\n",
    "\n",
    "\\begin{align}\n",
    "\\begin{split}\n",
    "\\min && \\; f_1(x)\\\\[2mm]\n",
    "\\min && \\; f_2(x) = g(x) \\, h(f_1(x),g(x))\n",
    "\\end{split}\n",
    "\\end{align}\n",
    "\n",
    "where two objective have to be minimized. The function $g(x)$ can be considered as the function for convergenece  and usually $g(x) = 1$ holds for pareto-optimal solutions (except for ZDT5).\n"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt1:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ZDT1\n",
    "\n",
    "This is a 30-variable problem ($n=30$) with a convex Pareto-optimal set:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f_1(x) &= \\, & x_1 \\\\\n",
    "g(x) &=& 1 + \\frac{9}{n-1} \\; \\sum_{i=2}^{n} x_i \\\\\n",
    "h(f_1,g) &=& 1 - \\sqrt{f_1/g} \\\\\n",
    "\\end{split}\n",
    "\\end{align}\n",
    "\n",
    "\n",
    "$$0 \\leq x_i \\leq 1 \\quad i=1,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0 \\leq x_1^* \\leq 1  \\quad \\text{and} \\quad x_i^*=0 \\; \\text{for} \\; i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Plot**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt1\")\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt2:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ZDT2\n",
    "\n",
    "This is also a 30-variable problem ($n=30$) with a non-convex Pareto-optimal set:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f_1(x) &= \\, & x_1 \\\\\n",
    "g(x) &=& 1 + \\frac{9}{n-1} \\; \\sum_{i=2}^{n} x_i \\\\\n",
    "h(f_1,g) &=& 1 - (f_1/g)^2 \\\\\n",
    "\\end{split}\n",
    "\\end{align}\n",
    "\n",
    "\n",
    "$$0 \\leq x_i \\leq 1 \\quad i=1,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0 \\leq x_1^* \\leq 1  \\quad \\text{and} \\quad x_i^*=0 \\; \\text{for} \\; i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Plot**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt2\")\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt3:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ZDT3\n",
    "\n",
    "This is also a 30-variable problem ($n=30$) with a number of disconnected Pareto-optimal fronts:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f_1(x) &= \\, & x_1 \\\\\n",
    "g(x) &=& 1 + \\frac{9}{n-1} \\; \\sum_{i=2}^{n} x_i \\\\\n",
    "h(f_1,g) &=& 1 - \\sqrt{f_1/g} - (f_1/g) \\; \\sin(10\\pi f_1)\\\\\n",
    "\\end{split}\n",
    "\\end{align}\n",
    "\n",
    "\n",
    "$$0 \\leq x_i \\leq 1 \\quad i=1,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0 \\leq x_1^* \\leq 0.0830 \\\\\n",
    "0.1822 \\leq x_1^* \\leq 0.2577\\\\\n",
    "0.4093 \\leq x_1^* \\leq 0.4538 \\\\\n",
    "0.6183 \\leq x_1^* \\leq 0.6525 \\\\\n",
    "0.8233 \\leq x_1^* \\leq 0.8518 \\\\\n",
    "x_i^*=0 \\; \\text{for} \\; i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Plot**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt3\")\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt4:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ZDT4\n",
    "\n",
    "This is a 10-variable ($n=10$) problem having a convex Pareto-optimal set. There exist many local Pareto-optimal solutions in this problem. Therefore, algorithms can easily get stuck in a local optimum."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f_1(x) &= \\, & x_1 \\\\\n",
    "g(x) &=& 1 + 10(n-1) + \\sum_{i=2}^{n} (x_i^2 - 10 \\cos(4\\pi x_i))\\\\\n",
    "h(f_1,g) &=& 1 - \\sqrt{f_1/g}\\\\\n",
    "\\end{split}\n",
    "\\end{align}\n",
    "\n",
    "\n",
    "$$0 \\leq x_1 \\leq 1 \\\\\n",
    "-10 \\leq x_i \\leq 10 \\quad i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0 \\leq x_1^* \\leq 1  \\quad \\text{and} \\quad x_i^*=0 \\; \\text{for} \\; i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Plot**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt4\")\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt5:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ZDT5\n",
    "\n",
    "In ZDT5 in variables are decodec by bitsrings. At all 11 discrete variables are used, where $x_1$ is represented by 30 bits and the rest $x_2$ to $x_{11}$ by 5 bits each. The function $u(x)$ does nothing else than count the number of $1$ of the corresponding variable. Also, note that the objective function is deceptive, because the values of $v(u(x_i))$ are decreasing with the number of 1's, but has its minimum when all variables are indeed 1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f_1(x) &= \\, & 1+u(x_1)\\\\\n",
    "g(x) &=& \\sum_{i=2}^{n} v(u(x_i))\\\\[2mm]\n",
    "v(u(x_i)) &=&\n",
    "\\begin{cases}\n",
    "2 + u(x_i) \\quad \\text{if} \\; u(x_i) < 5\\\\\n",
    "1 \\quad \\quad \\quad \\; \\; \\; \\text{if} \\; u(x_i) = 5\n",
    "\\end{cases}\\\\[4mm]\n",
    "h(f_1,g) &=& 1 /f_1(x)\\\\[2mm]\n",
    "\\end{split}\n",
    "\\end{align}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0 \\leq u(x_1^*) \\leq 30  \\quad \\text{and} \\quad u(x_i^*)=5 \\; \\text{for} \\; i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Plot**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt5\", normalize=False)\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Please note that by default here the Pareto-front is not normalized. However, this can be easily achived normalizing $f_1$ in the range of $(1,31)$ and $f_2$ in $(10/31, 10)$ which are the known bounds of the Pareto-set. By default the normalized problem is used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt5\", normalize=False)\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_zdt6:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ZDT6\n",
    "\n",
    "This is a 10-variable ($n=10$) problem having a nonconvex Pareto-optimal set. The density of solutions across the Pareto-optimal region is non-uniform."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Definition**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\\begin{align}\n",
    "\\begin{split}\n",
    "f_1(x) &= \\, & 1 - \\exp(-4 x_1) \\sin^6 (6 \\pi x_1) \\\\[2mm]\n",
    "g(x) &=& 1 + 9 \\bigg[\\bigg( \\sum_{i=2}^{n} x_i \\bigg) / 9\\bigg]^{0.25}\\\\[2mm]\n",
    "h(f_1,g) &=& 1 - (f_1/g)^2\\\\\n",
    "\\end{split}\n",
    "\\end{align}\n",
    "\n",
    "\n",
    "$$0 \\leq x_i \\leq 1 \\quad i=1,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Optimum**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0 \\leq x_1^* \\leq 1  \\quad \\text{and} \\quad x_i^*=0 \\; \\text{for} \\; i=2,\\ldots,n$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Plot**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.plotting import plot\n",
    "\n",
    "problem = get_problem(\"zdt6\")\n",
    "plot(problem.pareto_front(), no_fill=True)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
